<template>
  <ma-form-modal ref="formModal" v-if="visible" v-bind="addParcels" @cancel="visible=false"></ma-form-modal>
</template>
<script setup>
import maFormModal from '@cps/ma-form-modal/index.vue'
import {inject, nextTick, onMounted, ref, watch} from "vue";
import waybill from "@/api/document/waybill.js";
import {Message} from "@arco-design/web-vue";

const crudRef = inject('crudRef')
const record = inject('record')
const getRecord = inject('getRecord')
const visible = defineModel()
const formModal = ref()
const addParcels = ref({
  default_visible: true,
  // width: '60%',
  title: '添加货箱/运单',
  options:{
    layout:'vertical'
  },
  columns: [
    {
      formType: 'grid',
      gutter:24,
      cols: [
        {
          formList: [{
            title: '运单号',
            dataIndex: 'shipment',
            formType: 'textarea',
            autoSize: {minRows:5}
          }]
        },
        {
          formList: [{
            title: '箱号',
            dataIndex: 'parcel',
            formType: 'textarea',
            autoSize: {minRows:5}
          }]
        },

      ]
    },
  ],
  submit: async (v) => {
    v.waybill_id = record.value.id
    let result = await waybill.addParcel(v)
    if(!result.success){
      Message.error(result.message)
      return false
    }
    crudRef.value.refresh()
    visible.value = false
    await getRecord()
    return true;
  }
})
</script>